﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json.Serialization;
using System.Threading.Tasks;

namespace StableDiffusionTools.Oobabooga
{
    public class Message
    {
        [JsonPropertyName("role")]
        public Role Role { get; set; }
        [JsonPropertyName("content")]
        public string Content { get; set; }

        protected Message()
        {

        }
        public Message(Role role, string content)
        {
            Role = role;
            Content = content;
        }
        public override string ToString()
        {
            return $"{Role}: {Content}";
        }
        public string FormatMessage()
        {
            return $"{Role}:\r\n{Content}";
        }

        public void FixToApi()
        {
            Content = FixToApi(Content);
        }

        public void FixFromApi()
        {
            Content = FixFromApi(Content);
        }

        public static string FixToApi(string content)
        {
            return content.Replace("\r\n", "\n");
        }

        public static string FixFromApi(string content)
        {
            return content.Replace("\r\n", "\n").Replace("\n", "\r\n");
        }
    }
}
